import os
def key(list2,key_name):   
    for 文档 in range(len(list2)):
        f1 = open(list2[文档],'r')
        f1.seek(0,0)
        line = 0
        loca = []
        for nr_line in f1:
            line +=1
            if key_name in nr_line:
                for 次数 in range(1,(nr_line.count(key_name))+1):
                    (x,y,z)=nr_line.partition(key_name)
                    if len(x) != 0:
                        loca.append(len(x))
                    else :
                        loca.append(1)              
                    nr_line = '   '+x+z
                print('在%s' %(list2[文档]))
                print('关键字出现在第%d行,第%s位置'%(line,loca))
                loca = []
def k_loca():
    list1 = list(os.walk(os.curdir))
    list2 = []
    lentgh1 =len(list1)
    for i in range(lentgh1):
        lentgh2 = len(list1[i])
        for j in range(1,lentgh2):
            for k in list1[i][j]:
                (x,y)=os.path.splitext(k)
                if y == '.txt':
                    name =k 
                    list2.append(name)
    return list2
key_name = str(input('请输入关键字'))
list2=k_loca()
key(list2,key_name)


            
        
